
Ext.BLANK_IMAGE_URL = 'images/default/s.gif';// 空白图片
Ext.QuickTips.init();// 代码提示，比如：<input type="button" value="OK"
// ext:qtitle="Test" ext:qtip="Test Content!">
var start = {
	id : 'start-panel',
	title : '欢迎使用',
	layout : 'fit',
	bodyStyle : 'padding:25px',
	html : '<img src="images/bg.jpg"/>'
};


var themes=new Ext.data.SimpleStore({
    fields:['theme','css'],
    data:[
	         ['默    认','ext-all.css'],
	         ['咖啡色','xtheme-human.css'],
	         ['银红色','xtheme-silverCherry.css'],
	         ['浅灰色','xtheme-tp.css'],
	         ['亮黑色','xtheme-slickness.css'],
	         ['纯黑色','xtheme-dcs.css'],
	         ['蓝灰色','xtheme-slate.css']
	   ]
});

function escapeHTML(html){
	html = html.replace(/\&/g,"&amp;");
	html = html.replace(/\>/g,"&gt;");
	html = html.replace(/\</g,"&lt;");
	html = html.replace(/\"/g,"&quot;");
	return html ;
}

var color_change=new Ext.form.ComboBox({
    triggerAction:"all",
    fieldLabel:'切换系统皮肤',
    forceSelection:true,
    typeAhead:true,
    emptyText:"切换系统皮肤",
    width:195,
    store:themes,
    displayField:"theme",
    valueField:"css",
    mode:"local",
    editable:false,
    listeners:{
            'select':function(e){            	
	             var conboBoxValue=color_change.getValue();
	             new Ext.state.CookieProvider().set('color',conboBoxValue);
	             Ext.util.CSS.swapStyleSheet(
		            'theme',
		            'css/'+conboBoxValue
	              );
            }
    }
});


Ext.onReady(function() {
	setTimeout(function() {
		Ext.get('loading').remove();
		Ext.getDom('header').style.visibility = 'visible';
		var vp = new Ext.Viewport({
			layout : 'border',
			defaults : {
				collapsible : true,
				split : true
			},
			items : [{
						xtype : 'box',
						region : 'north',
						applyTo : 'header',
						height : 60,
						split : false
					}, {
						region : 'south',
						contentEl : 'south',
						split : false,
						height : 28,
						minSize : 28,
						maxSize : 28,
						collapsible : false,
						margins : '0 0 0 0'
					}, {
						title : currentUser,
						id : 'accordion-panel',
						layout : 'border',
						region : 'west',
						margins : '2 0 5 5',
						width : 200,
						minSize : 200,
						maxSize : 250,
						bodyStyle : 'background-color:#DFE8F6',
						defaults : {
							border : false
						},
						bbar:[color_change],
						items : [{
							layout : 'accordion',
							region : 'center',
							items : [{
								title : '导航菜单',
								iconCls : 'icon-nav',
								border : false,
								items : [{
									xtype : 'treepanel',
									border : false,
									rootVisible : false,
									autoScroll : true,
									loader : new Ext.tree.TreeLoader({
										dataUrl :  'js/' + nav + '/tree-data-manager.json'
											}),
									root : new Ext.tree.AsyncTreeNode(),
									listeners : {
										'click' : function(module) {// module为叶子节点
											try {// 目的：动态加载外部js
												var sn = this.selModel.selNode
														|| {};
												if (module.leaf
														&& module.id != sn.id) {
													// pid为父模块的名字
													var pid = module.id
															.substring(
																	0,
																	module.id
																			.indexOf('-'));
													var contentPanel = Ext
															.getCmp('content-panel');
													// 缓存模块实现：首先判断该是否已经加载过，如果加载了，则设置为激活状态。
													if (contentPanel.uxmodules != undefined
															&& contentPanel.uxmodules[module.id]) {
														contentPanel.layout
																.setActiveItem(module.id);
														return;
													}
													var onLoadJs = function(
															response) {
														eval(response.responseText);
														// 这里定义一下contentPanel.uxmodules
														if (contentPanel.uxmodules == undefined) {
															contentPanel.uxmodules = new Ext.util.MixedCollection();
														}
														contentPanel.uxmodules[module.id] = module.id;
													};
													Ext.Ajax.request({
														url : 'js' + path + '/'
																		+ pid
																		+ '/'
																		+ module.id
																		+ '.js',
																success : onLoadJs,
																method : 'GET'
															});
												}
											} catch (e) {
											}
										}
									}
								}]
							}]
						}]
					}, {
						id : 'content-panel',
						region : 'center',
						layout : 'card',
						margins : '2 5 5 0',
						collapsible: false,
						activeItem : 0,
						border : false,
						items : [start]
					}]
		});
		var css=new Ext.state.CookieProvider().get('color');
   	Ext.util.CSS.swapStyleSheet(
		            'theme',
		            'css/'+css
	              );
	}, 250);

});


